﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using diploma.core.data;
using diploma.core.data.objects;

namespace diploma.test.core
{
    public class TestItem
    {
        public static Question GetItem(List<Question> _items)
        {
            int n = Enum.GetValues(typeof(QuestionTypes)).Length;
            Random rand = new Random();
            int qType = rand.Next(0, n - 1);
            qType = 6;
            Question tmp = null;
            switch ((QuestionTypes)qType)
            {
                case QuestionTypes.Binds:
                case QuestionTypes.Difficult:
                case QuestionTypes.Exact:
                case QuestionTypes.Single:
                case QuestionTypes.YesNo:
                    DataList<IDataObject> properties = TestManager.Instance.Collection[diploma.core.data.DataObjectTypes.Property];
                    break;
                case QuestionTypes.Term:
                    DataList<IDataObject> terms = TestManager.Instance.Collection[DataObjectTypes.Term];
                    DataList<IDataObject> statements = TestManager.Instance.Collection[DataObjectTypes.Statement];
                    DataList<IDataObject> theorems = TestManager.Instance.Collection[DataObjectTypes.Theorem];
                    int t = rand.Next(0, 1);
                    if (t == 0)
                    {
                        tmp = new TermQuestion("fill_empty_spaces", (theorems[rand.Next(0, theorems.Count - 1)] as Theorem).Formulation, terms, 2);
                    }
                    else
                    {
                        tmp = new TermQuestion("fill_empty_spaces", (statements[rand.Next(0, statements.Count - 1)] as Statement).Content, terms, 2);
                    }
                    foreach (Question q in _items)
                    {
                        if (q is TermQuestion)
                        {
                            if ((q as TermQuestion).Term.ToLower().Trim() == (tmp as TermQuestion).Term.ToLower().Trim())
                            {
                                tmp = null;
                            }
                        }
                    }
                    if (tmp!= null && (tmp as TermQuestion).RightAnswer.Length == 0) tmp = null;
                    break;
                case QuestionTypes.Complex:
                    break;
                case QuestionTypes.Undefined:
                default:
                    break;
            }

            return tmp;
        }
    }
}
